package com.example.spring.job;

import com.example.autojob.skeleton.annotation.IMethodTaskFactory;
import com.example.autojob.skeleton.enumerate.SchedulingStrategy;
import com.example.autojob.skeleton.framework.config.AutoJobConfigHolder;
import com.example.autojob.skeleton.framework.config.AutoJobMailConfig;
import com.example.autojob.skeleton.framework.config.AutoJobRetryConfig;
import com.example.autojob.skeleton.framework.task.AutoJobTask;
import com.example.autojob.skeleton.model.builder.AutoJobMethodTaskBuilder;
import com.example.autojob.skeleton.model.task.method.MethodTask;
import com.example.autojob.util.id.IdGenerator;
import com.example.autojob.util.io.PropertiesHolder;

import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;

/**
 * @author Huang Yongxiang
 * @date 2023-01-11 11:48
 * @email 1158055613@qq.com
 */
public class WithMailConfigTaskFactory implements IMethodTaskFactory {
    @Override
    public MethodTask newTask(AutoJobConfigHolder configHolder, Method method) {
        long taskId = IdGenerator.getNextIdAsLong();
        return new AutoJobMethodTaskBuilder(method.getDeclaringClass(), method.getName())
                .setRetryConfig(new AutoJobRetryConfig(true, Integer.MAX_VALUE, 0, taskId))
                .setMailConfig(new AutoJobMailConfig(PropertiesHolder
                        .builder()
                        .build()))
                .setParams("{'生日提醒','祝你生日快乐，宝贝！'}")
                .setTaskId(taskId)
                .setTaskType(AutoJobTask.TaskType.DB_TASK)
                .setSchedulingStrategy(SchedulingStrategy.JOIN_SCHEDULING)
                .addADelayTrigger(12, TimeUnit.SECONDS)
                .build();
    }
}
